package cobaKoneksi;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DemoKoneksi {
	public static void main(String[] args) throws Exception{
		connect();
	}
	
	public static void connect() throws Exception{
		
		Class.forName("com.mysql.jdbc.Driver");
		
		
		String host = "localhost/test";
		String db = "test";
		String user = "root";
		String pass = "";
		//int port = 3036;
		String sql = "select * from product";
		
		String mysqlURL = "jdbc:mysql://localhost/test";
		
		Connection connect = DriverManager.getConnection(mysqlURL,user,pass);
		
		ResultSet rs = connect.createStatement().executeQuery(sql);
		
		DatabaseMetaData metadata = connect.getMetaData();
		System.out.println("Database : " + metadata.getDatabaseProductName());
		
		while(rs.next()){
			System.out.println("id = "+rs.getInt(1));
			System.out.println("nama produk = "+rs.getString(2));
		}
	}
}
